<?php

namespace app\api\model;

use think\Model;

class DesignServices extends Model
{
    protected $hidden = ['online', 'createtime', 'updatetime'];

    /**
     * 获取造型服务最低价
     */
    public static function getDesignMin($design_id)
    {
        return self::where('online', 'yes')->where('design_id', $design_id)->min('price');
    }

    public function service()
    {
        return $this->hasOne(ModelingServices::class, 'id', 'service_id');
    }

    /**
     * 服务项目
     */
    public static function getServices($id)
    {
        return self::with('service')->find($id);
    }

    public static function getPriceById($design_service_id)
    {
        return self::where('id', $design_service_id)->value('price');
    }

    public static function getServicesByDesign($design_id, $user_id)
    {
        $design_services = self::with('service')->where('design_id', $design_id)->where('online', 'yes')->order('weigh desc')->select();
        foreach ($design_services as $val) {
            $val['vip_price'] = number_format($val['price'] * Users::getVipDiscount($user_id), 2);
        }
        return $design_services;
    }
}
